$(document).ready(function(){

	getWeeeklySpecials();//获取每周精选
	getWineCorner();//获取酒品
	getHampers();//getHampers
	lookDetail();
	addSlideFun();
});
//获取每周精选
function getWeeeklySpecials(){
	var shopDas = MPJ.getShopData();
	var arr={
		hf_s_id:"WD11",
		hf_srv_id:"Pv_jpdt_get_all_ddc",
		hs_action_id:"submit",
		hs_srch_item_no: shopDas.Home.ManagersSpecials.replace(/,/g,' ')
	};
	getAjaxRequest(arr,function(result){
		var productArr=setProductList_index(result);
		$('.slideBox.vertical-list').eq(0).find("ul").html(productArr[0]);


	}, null, true);
}
function getWineCorner(){
	var shopDas = MPJ.getShopData();
	var arr={
		hf_s_id:"WD11",
		hf_srv_id:"Pv_jpdt_get_all_ddc",
		hs_action_id:"submit",
		hs_srch_item_no: shopDas.Wine.TopPicks.replace(/,/g,' ')
	};
	getAjaxRequest(arr,function(result){
		var productArr=setProductList_index(result);
		$('.slideBox.vertical-list').eq(1).find("ul").html(productArr[0]);
	}, null, true);
}

function getHampers(){
	var arr={
		hf_s_id:"WD11",
		hf_srv_id:"Pv_jpo_dtl_get",
		hs_action_id:"submit",
		hs_po_id:"HAMPERS",
		hf_locale_id:"en"
	};
	getAjaxRequest(arr,function(result){
		if (result.bs_result == BS_RESULT.OK) {
			var str='';
			var bvc_pdt = result.bc_group_a_pdt.bvc_pdt;
			if(bvc_pdt.length != 0){
				for (var j = 0; j < bvc_pdt.length; j ++) {
					var product = bvc_pdt[j];
					var isOffer= product.bs_is_offer == "Y" ? '<span><em>offer</em></span>' : '';
					var bs_prom_text=product.bs_prom_text == "" ? "" : product.bs_prom_text;
					str+='<li data-id="'+product.bj_pdt_id+'" data-item-no="'+product.bs_item_no+'">'+
						'<div class="mainCon">'+
						'<div class="imgBox">'+
						'<img src="'+MPJ.apiBase+''+product.bs_simg_file+'" />'+isOffer+
						'</div>'+
						'<div class="txtBox">'+
						'<h4>'+product.bs_brand+'</h4>'+
						'<p>'+product.bs_desc+'</p>'+
						'<div class="red-font">'+bs_prom_text +'</div>'+
						'<div class="price orange-font">$<em>'+product.bj_rsp+'</em></div>'+
						'<div class="num">'+
						'<div class="mui-numbox" data-numbox-min="1" >'+
						'<button class="mui-btn mui-numbox-btn-minus" type="button">-</button>'+
						'<input class="mui-numbox-input" type="number" value="1" />'+
						' <button class="mui-btn mui-numbox-btn-plus" type="button">+</button>'+
						'</div>'+
						'<div class="addCar">'+
						'Add<img src="' + MPJ.base + '/resources/images/icon/main-shopcar.png" />'+
						'</div>'+
						'</div>'+
						'</div>'+
						'</div>'+
						'</li>';
				}
			}
			$('.slideBox.vertical-list').eq(2).find("ul").html(str);
		}
	}, null, true);
}
function lookDetail(){
	//两列数据的列表点击
	$('.vertical-list li').each(function(){
		var $this=$(this);
		$this.on('tap','.imgBox',function(){
			var pdt_id=$this.data('id');
			var item_no=$this.data('item-no');
			var product_info={};
			product_info.pdt_id=pdt_id;
			product_info.item_no=item_no;
			sessionStorage.setItem('product_info',JSON.stringify(product_info));
			location.href=MPJ.base+"/pages/product/product-detail.jsp";
		})
		$this.on('tap','.addCar',function(){
			var pdt_id=$this.data('id');
			var item_no=$this.data('item-no');
			var arr={
				hf_s_id:"WD11",
				hf_srv_id:"Av_jcart",
				hs_action_id:"add_all_to_cart",
				hvs_add_pdt_id:pdt_id,
				hvs_add_qty:$this.find('.mui-numbox-input').val(),
			};
			getAjaxRequest(arr,function(result){
				if(result.bs_result==BS_RESULT.OK){
					dialog('Message', 'Add to Shopping Cart', 1);
					var $dialog = $('#dialog');
					$dialog.show();
					$dialog.find('.comfirmBtn').one('click', function() {
						$dialog.hide();
						$dialog.remove();
						getCartSumCount();
					})
				}
			});

		})
	})

}

$('.classify .title span.weekly-special').on('tap',function(){
	sessionStorage.removeItem('category_Arr');
	var category_Arr = [];

	var dpm_classify = {};
	dpm_classify.id = "406";
	dpm_classify.name = "Weekly Specials";

	category_Arr.push(dpm_classify);
	sessionStorage.setItem('category_Arr', JSON.stringify(category_Arr));
	location.href =  MPJ.base+"/pages/product/product-list.jsp";
})

$('.classify .title span.wine-corner').on('tap',function(){
	location.href =  MPJ.base+"/pages/wine/wine-corner.jsp";
})
$('.classify .title span.hampers').on('tap',function(){
	window.location.href =  MPJ.base+'/pages/hampers.jsp';
})




$('#department_index').on('tap',function(){
	location.href=MPJ.base+"/pages/product/classify.jsp";
})


$('#findStore_index').on('tap',function(){
	location.href=MPJ.base+"/pages/store/find-a-store.jsp";
})
$('#weekly_special_index').on('tap',function(){
	location.href=MPJ.base+"/pages/product/weekly-specials.jsp";
})
//点击wine corner
$('#wine_corner_index').on('tap',function(){
	location.href=MPJ.base+"/pages/wine/wine-corner.jsp";
})
$('#features_index').on('tap',function(){
	window.location.href =  MPJ.base+'/pages/other/features.jsp';
})
//预定
$('#pre_orders_index').on('tap',function(){
	window.location.href =  MPJ.base+'/pages/pre-order.jsp';
})
$('#popular_brands_index').on('tap',function(){
	window.location.href =  MPJ.base+'/pages/popular-brand.jsp';
})

$('#orders_index').on('tap',function(){
	window.location.href =  MPJ.base+'/pages/account/order/list.jsp';
})

